home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <graphics.h>
-
- main()
- {
- int graphdriver = DETECT, graphmode, x1, x2, y1, y2, maxx, maxy, maxcolor;
- /* Detect adapter type and initialize graphics system */
- initgraph(&graphdriver, &graphmode, "c:\\turboc");
- outtextxy(10,10, "animating a line using 'setwritemode'");
- maxx = getmaxx()-100;
- maxy = getmaxy()-60;
- maxcolor = getmaxcolor();
- randomize(); /* Initialize random number generator */
- /* Exit when user presses a key */
- outtextxy(10, getmaxy()-30, " Press any key to exit");
- while (!kbhit())
- {
- /* Generate random end points for the lines */
- x1 = random(maxx) + 50;
- x2 = random(maxx) + 50;
- y1 = random(maxy) + 30;
- y2 = random(maxy) + 30;
- setcolor(random(maxcolor));
- /* Now draw the line */
- setwritemode(COPY_PUT);
- line(x1,y1, x2,y2);
- /* and erase it by redrawing it in XOR_PUT mode */
- setwritemode(XOR_PUT);
- line(x1,y1, x2,y2);
- }
- closegraph();
- }